#include "ReagentManageSetView.h"
#include "ui_ReagentManageSetForm.h"
#include "GlobalApi/SqliteDb.h"

ReagentManageSetView::ReagentManageSetView(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ReagentManageSetView)
{
    ui->setupUi(this);
    InitTable();
}

ReagentManageSetView::~ReagentManageSetView()
{
    delete ui;
}

void ReagentManageSetView::InitTable()
{
    tableView = new QTableView(this);
    ui->gLayout_userTable->addWidget(tableView);
    tableView->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
    tableView->horizontalHeader()->setStretchLastSection(true);
    tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
    tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
    tableView->setSelectionMode(QAbstractItemView::SingleSelection);
    tableView->horizontalHeader()->setClickable(false); //设置表头不可点击（默认点击后进行排序）
    tableView->setFrameShape(QFrame::NoFrame);
    tableView->setShowGrid(false);
    tableView->horizontalHeader()->setFixedHeight(30);
    tableView->verticalHeader()->setFixedWidth(40);
    tableView->horizontalHeader()->setStyleSheet("QHeaderView::section{background:rgb(102, 204, 153);gridline-color: rgb(255, 255, 255);border:1px solid#C9C9C9;}"); //设置表头背景色
    tableView->verticalHeader()->setStyleSheet("QHeaderView::section{background:rgb(102, 204, 153);gridline-color: rgb(255, 255, 255);border:1px solid#C9C9C9;}"); //设置表头背景色
    tableView->setColumnWidth(0,350);
    tableView->setAlternatingRowColors(true);//间隔显示颜色

    QString stylesheettableWidget_listing = "QTableWidget{background-color:#ffffff;"
            "alternate-background-color: #e2f7eb;"
            "color: rgb(0, 0, 0);"
            "selection-color: rgb(255, 255, 255);"
            "selection-background-color: rgb(32, 131, 95);}"
            "QTableCornerButton::section{background:rgb(102, 204, 153);"
            "gridline-color: rgb(255, 255, 255);"
            "border:1px solid#c9c9c9;}";
    tableView->setStyleSheet(stylesheettableWidget_listing);

    model = new MySqlTableModel(this, SqliteDb::getInstance()->getDB());
    model->setTable("reagentManager");
    model->removeColumn(0);
    model->select();

    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    tableView->setModel(model);
    model->setHeaderData(0, Qt::Horizontal, tr("更换"));
    model->setHeaderData(1, Qt::Horizontal, tr("试剂名称"));
    model->setHeaderData(2, Qt::Horizontal, tr("开瓶日期"));
    model->setHeaderData(3, Qt::Horizontal, tr("失效日期"));
    model->setHeaderData(4, Qt::Horizontal, tr("余量"));
}

void ReagentManageSetView::closeEvent(QCloseEvent *e)
{
    Q_UNUSED(e);
}

void ReagentManageSetView::on_Btn_set_clicked()
{
    int row = tableView->currentIndex().row();
    ReagentInfoDialog *m_reagentIfo = new ReagentInfoDialog(row, model, this);
    m_reagentIfo->move(60,60);
    m_reagentIfo->show();
}
